package ch9;

//3:老师有年龄，学校，姓名的属性，有上课和自我介绍的方法，如果年龄少于22岁，抛出异常。
public class Teacher {
    private String name, school;
    private int age;

    public Teacher() {
    }

    public Teacher(String name, String school, int age) throws Exception {
        if (age < 22) {
            throw new Exception("年龄小于22。");
        }
        this.name = name;
        this.school = school;
        this.age = age;
    }

    public void attendClass() {
        System.out.println(this.name + "老师使用idea软件教学生学习java。");
    }

    public void introduction() {
        System.out.println("我叫" + this.name + "，今年" + this.age + "岁，是" + this.school + "的老师。");
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSchool() {
        return school;
    }

    public void setSchool(String school) {
        this.school = school;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) throws Exception {
        if (age < 22) {
            throw new Exception("年龄小于22。");
        }
        this.age = age;
    }
}
